package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try (
                Connection connection= DBUtil.getConnection();
        ){
            Statement statement=connection.createStatement();
//            String sql="SELECT s.id,s.name,s.job,c.id,c.floor "+
//                       "FROM student s,class c "+
//                       "WHERE s.class_id=c.id "+
//                       "AND c.name='1年级1班'";

            String sql="SELECT s.id,s.name,s.job,c.id,c.floor "+
                       "FROM student s "+
                       "JOIN class c ON s.class_id=c.id "+
                       "WHERE c.name='1年级1班'";
            ResultSet rs=statement.executeQuery(sql);
            while (rs.next()){
                int sId=rs.getInt("s.id");
                String sName=rs.getString("s.name");
                String sJob=rs.getString("s.job");
                int cId=rs.getInt("c.id");
                String cFloor=rs.getString("c.floor");
                System.out.println(sId+","+sName+","+sJob+","+cId+","+cFloor);
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
